package cn.edu.sdu.sol.intake_system.utils;

import cn.edu.sdu.sol.intake_system.model.po.Gender;
import cn.edu.sdu.sol.intake_system.model.po.PersonInf;
import cn.edu.sdu.sol.intake_system.model.vo.DataRequest;
import org.springframework.stereotype.Component;

import java.text.ParseException;
import java.util.Date;

@Component
public class PersonInfUtils {

    public void fillPerson(PersonInf oldInf, DataRequest req){
        String name = req.getString("name");
        Integer genderInt = req.getInteger("gender");
        Gender gender = Gender.UNKNOWN;
        if(genderInt != null){
            if(genderInt == 0){
                gender = Gender.MALE;
            } else if(genderInt == 1){
                gender = Gender.FEMALE;
            }
        }
        Date birthday = req.getDate("birthday");
        String academy = req.getString("academy");
        String profession = req.getString("profession");
        String qq = req.getString("qqNum");
        String phone = req.getString("phoneNum");
        String email = req.getString("email");
        String birthPlace = req.getString("birthplace");
        String introduce = req.getString("introduction");
        String school = req.getString("school");
        if (name != null && !name.equals("")) {
            oldInf.setName(name);
        }
        if(genderInt != null) {
            oldInf.setGender(gender);
        }
        if (birthday != null) {
            oldInf.setBirthday(birthday);
        }
        if (academy != null && !academy.equals("")) {
            oldInf.setAcademy(academy);
        }
        if (profession != null && !profession.equals("")) {
            oldInf.setProfession(profession);
        }
        if (qq != null && !qq.equals("")) {
            oldInf.setQqNum(qq);
        }
        if (phone != null && !phone.equals("")) {
            oldInf.setPhoneNum(phone);
        }
        if (email != null && !email.equals("")) {
            oldInf.setEmail(email);
        }
        if (birthPlace != null && !birthPlace.equals("")) {
            oldInf.setBirthPlace(birthPlace);
        }
        if (introduce != null && !introduce.equals("")) {
            oldInf.setIntroduction(introduce);
        }
        if (school != null && !school.equals("")) {
            oldInf.setSchool(school);
        }
    }

}
